package cc.booku.owlbox.Classify;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import cc.booku.owlbox.ArtDesign.SystemUtil;
import cc.booku.owlbox.FileOperations.FileoOperations;
import cc.booku.owlbox.R;
import cc.booku.owlbox.RsaUtil.Decrypt;
import cc.booku.owlbox.VideoPlayer.VideoPlayerActivity;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class ClassifyActivity extends AppCompatActivity implements ObservableScrollView.ScrollViewListener {
    private Toolbar Toolbar;
    private TextView tv_class, tv_year, tv_lang, tv_area, topPanel, httpdata;
    private GridView CustomizeGridview;
    private LinearLayout Tv_label;
    private String ClassifyPath = Environment.getExternalStorageDirectory() + File.separator + "OwlDatabase" + File.separator + "UserData/Classify.txt";
    private List<vod_class_C> vod_class_cArrayList = new ArrayList<vod_class_C>();
    private List<vod_area_C> vod_area_cArrayList = new ArrayList<vod_area_C>();
    private List<vod_lang_C> vod_lang_cArrayList = new ArrayList<vod_lang_C>();
    private List<vod_year_C> vod_year_cArrayList = new ArrayList<vod_year_C>();
    private List<Customize_C> customizeCList = new ArrayList<Customize_C>();
    private HorizontalListView vod_class, vod_lang, vod_area, vod_year;
    private ObservableScrollView scrollView;
    private Customize_A customizeA;
    private Customize_C customizeC;

    private vod_class_A vodClassA;
    private vod_lang_A vodLangA;
    private vod_area_A vodAreaA;
    private vod_year_A vodYearA;

    private vod_class_C vod_class_c;
    private vod_area_C vod_area_c;
    private vod_lang_C vod_lang_c;
    private vod_year_C vod_year_c;
    private String ProfilePath = Environment.getExternalStorageDirectory() + File.separator + "OwlDatabase" + File.separator + "Profile.txt";
    private String filePath = Environment.getExternalStorageDirectory() + File.separator + "OwlDatabase" + File.separator + "UserData" + File.separator + "SearchOffline" + File.separator;
    private int topHeight;
    private LinearLayout ll_classify;

    //private String t_class,t_year,t_lang,t_area;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_classify);
        Tv_label = (LinearLayout) findViewById(R.id.tv_label);
        scrollView = (ObservableScrollView) findViewById(R.id.scrollView);
        ll_classify = (LinearLayout) findViewById(R.id.ll_classify);
        tv_class = (TextView) findViewById(R.id.tv_class);
        tv_year = (TextView) findViewById(R.id.tv_year);
        tv_lang = (TextView) findViewById(R.id.tv_lang);
        tv_area = (TextView) findViewById(R.id.tv_area);
        httpdata = (TextView) findViewById(R.id.httpdata);

        vod_class = (HorizontalListView) findViewById(R.id.vod_class);
        vod_lang = (HorizontalListView) findViewById(R.id.vod_lang);
        vod_area = (HorizontalListView) findViewById(R.id.vod_area);
        vod_year = (HorizontalListView) findViewById(R.id.vod_year);
        CustomizeGridview = (GridView) findViewById(R.id.gv_customize);
        initVodclass();


        //String vod_class,String vod_area,String vod_year,String vod_lang
        init_Customize(ClassifyUrl("", "", "", ""));
        //加载标题栏
        LoadToolbar();
        //状态栏颜色
        SystemUtil.setStatusBarColor(this, Color.parseColor("#448aca"));


        topPanel = (TextView) findViewById(R.id.topPanel);
        topPanel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                scrollView.scrollTo(0, 0);


            }
        });


        scrollView.setScrollViewListener(this);
    }


    private String ClassifyUrl(String vod_class, String vod_area, String vod_year, String vod_lang) {


        String ConfigFiles_json = FileoOperations.readAssetsTxt(ClassifyActivity.this, "TxtData/ConfigFiles");
        JSONObject objsd = JSONObject.parseObject(ConfigFiles_json);
        String ciphertext = objsd.getString("ADDRESSCIPHER");//地址密文
        String DecryptionAddress = Decrypt.RsaDecrypt(ClassifyActivity.this, ciphertext);
        String classify = objsd.getString("CLASSIFY");//分类筛选
        return DecryptionAddress + classify + "vod_class=" + vod_class + "&vod_year=" + vod_year + "&vod_lang=" + vod_lang + "&vod_area=" + vod_area;


//
//
//        String ProfileStr = FileoOperations.readFromSDFile(this, ProfilePath);
//        //读取配置文件信息
//        try {
//            JSONObject obj = JSONObject.parseObject(ProfileStr);
//            String result = obj.getString("分类筛选");
//            String ciphertext = obj.getString("地址密文");
//            String res = Decrypt.RsaDecrypt(ClassifyActivity.this, ciphertext);
//            return res+result+"vod_class="+vod_class+"&vod_year="+vod_year+"&vod_lang="+vod_lang+"&vod_area="+vod_area;
//        } catch (Exception e) {
//
//
////异常处理
//            }
//
//        return null;
    }


    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);

        Rect frame = new Rect();
        getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
        int statusBarHeight = frame.top;//状态栏高度

        int titleBarHeight = getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();//标题栏高度
        topHeight = titleBarHeight + statusBarHeight;
    }


    @Override
    public void onScrollChanged(ObservableScrollView scrollView, int x, int y, int oldx, int oldy) {
        int[] location = new int[2];
        Tv_label.getLocationOnScreen(location);
        int locationY = location[1];
        Log.e("locationY", locationY + "   " + "topHeight的值是：" + topHeight);

        if (locationY <= topHeight && (topPanel.getVisibility() == View.GONE || topPanel.getVisibility() == View.INVISIBLE)) {
            topPanel.setVisibility(View.VISIBLE);
            ll_classify.setVisibility(View.GONE);
        }

        if (locationY > topHeight && topPanel.getVisibility() == View.VISIBLE) {
            topPanel.setVisibility(View.GONE);
            ll_classify.setVisibility(View.VISIBLE);
        }
//        Message msg = new Message();
//        msg.what = 25;
//        Bundle bundle = new Bundle();
//        bundle.putInt("locationY", locationY);  //往Bundle中存放数据
//        bundle.putInt("topHeight", topHeight);  //往Bundle中存放数据
//        msg.setData(bundle);//mes利用Bundle传递数据
//        handler.sendMessage(msg);//用activity中的handler发送消息


    }


    public void CustomizeVideoData(ArrayList<Customize_C> customizeCS) {


        customizeA = new Customize_A(R.layout.customize_item, this, customizeCS);

        CustomizeGridview.setAdapter(customizeA);
        CustomizeGridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                //Toast.makeText(getContext(), "Click ++ item" + i, Toast.LENGTH_SHORT).show();
                final TextView vod_class1 = (TextView) view.findViewById(R.id.vod_class);
                final TextView vod_score1 = (TextView) view.findViewById(R.id.vod_score);
                final TextView vod_name1 = (TextView) view.findViewById(R.id.vod_name);
                final TextView vod_add_time1 = (TextView) view.findViewById(R.id.vod_add_time);
                final TextView vod_play_url1 = (TextView) view.findViewById(R.id.vod_play_url);
                final TextView vod_value_add1 = (TextView) view.findViewById(R.id.vod_value_add);
                final TextView vod_pic_url1 = (TextView) view.findViewById(R.id.vod_pic_url);

                String vod_class2 = vod_class1.getText().toString();
                String vod_score2 = vod_score1.getText().toString();
                String vod_name2 = vod_name1.getText().toString();
                String vod_add_time2 = vod_add_time1.getText().toString();
                String vod_play_url2 = vod_play_url1.getText().toString();
                String vod_value_add2 = vod_value_add1.getText().toString();
                String vod_pic_url2 = vod_pic_url1.getText().toString();

                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                bundle.putString("vod_class", vod_class2);
                bundle.putString("vod_score", vod_score2);
                bundle.putString("vod_name", vod_name2);
                bundle.putString("vod_add_time", vod_add_time2);
                bundle.putString("vod_play_url", vod_play_url2);
                bundle.putString("vod_value_add", vod_value_add2);
                bundle.putString("vod_pic", vod_pic_url2);
                intent.putExtras(bundle);
                intent.setClass(ClassifyActivity.this, VideoPlayerActivity.class);
                startActivity(intent);


            }
        });

    }


    private void init_Customize(String url) {

        customizeCList.clear();

        OkHttpClient client = new OkHttpClient();
        Request request = new Request
                .Builder()
                .url(url)//要访问的链接
                .build();

        Call call = client.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String res = response.body().string();
                httpdata.setText(res);
//                String jsonstr1 = res.replace("[{", "{");
//                String jsonstr2 = jsonstr1.replace("}]", "}");


//                Message msg = new Message();
//                msg.what = 16;
//                Bundle bundle = new Bundle();
//                bundle.putString("jsondata",res);  //往Bundle中存放数据
//                // bundle.putString("text2","Time：2016-11-03");  //往Bundle中put数据
//                msg.setData(bundle);//mes利用Bundle传递数据
//                handler.sendMessage(msg);//用activity中的handler发送消息

                try {
                    List<Customize_C> collectionStationCList = JSON.parseArray(res, Customize_C.class);
                    for (Customize_C normVideo : collectionStationCList) {
                        customizeC = new Customize_C();

//    vod_score  ---评分
//    vod_name	----影片名称
//    vod_class  ----类型
//    vod_pic ----图片地址
//    vod_play_url --视频地址
//    vod_add_time  ---添加日期

//    vod_actor ---演员
//    vod_director ---导演
//    vod_blurb  ---影片简介
//    vod_area  ---地区
//    vod_year  ---上映年份
//    vod_lang  ---语言

                        String vod_score = normVideo.getVod_score();
                        String vod_name = normVideo.getVod_name();
                        String vod_class = normVideo.getVod_class();
                        String vod_add_time = normVideo.getVod_add_time();
                        String vod_pic = normVideo.getVod_pic();
                        String vod_play_url = normVideo.getVod_play_url();

                        String vod_actor = normVideo.getVod_actor();
                        String vod_director = normVideo.getVod_director();
                        String vod_blurb = normVideo.getVod_blurb();
                        String vod_area = normVideo.getVod_area();
                        String vod_year = normVideo.getVod_year();
                        String vod_lang = normVideo.getVod_lang();
                        String vod_id = normVideo.getVod_id();

                        // Log.d("ImageviewHolder", "显示图片url======" + vod_pic);

                        customizeC.setVod_score("评分:" + vod_score);
                        customizeC.setVod_name(vod_name);
                        customizeC.setVod_class(vod_class + "#" + vod_year + "#" + vod_area + "#" + vod_lang + "#" + vod_id);
                        customizeC.setVod_add_time(vod_add_time);
                        customizeC.setVod_pic(vod_pic);
                        customizeC.setVod_pic_url(vod_pic);
                        customizeC.setVod_play_url(vod_play_url);
                        customizeC.setVod_value_add("导演：" + vod_director + "\n演员：" + vod_actor + "\n类型：" + vod_class + "\n上映地区：" + vod_area + "\n上映年份：" + vod_year + "\n语言：" + vod_lang + "\n$片名：" + vod_name + "\n剧情简介：" + vod_blurb);


                        customizeCList.add(customizeC);
                    }

                } catch (Exception e) {

                    Log.i("onResponse===========>", res);
//异常处理
                }


                Message msg = new Message();
                msg.what = 14;
                handler.sendMessage(msg);//用activity中的handler发送消息
            }
        });

    }


    private void initVodclass() {
        //读取json

        String ClassifyPathstr = FileoOperations.readAssetsTxt(ClassifyActivity.this, "TxtData/Classify");
//        JSONObject objsd = JSONObject.parseObject(BillBoard_B);
//        String result = objsd.getString("起始页小提醒");
        //  String ClassifyPathstr = FileoOperations.readFromSDFile(this, ClassifyPath);
        //读取配置文件信息
        JSONObject obj = JSONObject.parseObject(ClassifyPathstr);
        try {
            String result = obj.getString("vod_class");
            // Toast.makeText(ClassifyActivity.this, result, Toast.LENGTH_SHORT).show();
            // tv_test.setText(result);
            String[] str = result.split(",");
            for (String string : str) {
                vod_class_c = new vod_class_C();
                // System.out.println(string);
                vod_class_c.setClass_txt(string);
                vod_class_cArrayList.add(vod_class_c);
            }
            Message msg = new Message();
            msg.what = 2;
            handler.sendMessage(msg);//用activity中的handler发送消息

        } catch (Exception e) {
            // tv_test.setText("读取失败");
//异常处理
        }
        //解析json
        try {
            String result = obj.getString("vod_lang");
            // Toast.makeText(ClassifyActivity.this, result, Toast.LENGTH_SHORT).show();
            // tv_test.setText(result);
            String[] str = result.split(",");
            for (String string : str) {
                vod_lang_c = new vod_lang_C();
                // System.out.println(string);
                vod_lang_c.setLang_txt(string);
                vod_lang_cArrayList.add(vod_lang_c);
            }
            Message msg = new Message();
            msg.what = 4;
            handler.sendMessage(msg);//用activity中的handler发送消息

        } catch (Exception e) {
            // tv_test.setText("读取失败");
//异常处理
        }
        try {
            String result = obj.getString("vod_area");
            // Toast.makeText(ClassifyActivity.this, result, Toast.LENGTH_SHORT).show();
            //tv_test.setText(result);
            String[] str = result.split(",");
            for (String string : str) {
                vod_area_c = new vod_area_C();
                // System.out.println(string);
                vod_area_c.setArea_txt(string);
                vod_area_cArrayList.add(vod_area_c);
            }
            Message msg = new Message();
            msg.what = 6;
            handler.sendMessage(msg);//用activity中的handler发送消息

        } catch (Exception e) {
            // tv_test.setText("读取失败");
//异常处理
        }

        try {
            String result = obj.getString("vod_year");
            // Toast.makeText(ClassifyActivity.this, result, Toast.LENGTH_SHORT).show();
            //tv_test.setText(result);
            String[] str = result.split(",");
            for (String string : str) {
                vod_year_c = new vod_year_C();
                // System.out.println(string);
                vod_year_c.setYear_txt(string);
                vod_year_cArrayList.add(vod_year_c);
            }
            Message msg = new Message();
            msg.what = 8;
            handler.sendMessage(msg);//用activity中的handler发送消息

        } catch (Exception e) {
            // tv_test.setText("读取失败");
//异常处理
        }


    }


    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case 2:
                    vod_classClickListener((ArrayList<vod_class_C>) vod_class_cArrayList);
                    break;
                case 4:
                    vod_langClickListener((ArrayList<vod_lang_C>) vod_lang_cArrayList);
                    break;
                case 6:
                    vod_areaClickListener((ArrayList<vod_area_C>) vod_area_cArrayList);
                    break;
                case 8:
                    vod_yearClickListener((ArrayList<vod_year_C>) vod_year_cArrayList);
                    break;
                case 14:

                    CustomizeVideoData((ArrayList<Customize_C>) customizeCList);
                    break;

                case 25:
                    int locationY = msg.getData().getInt("locationY");
                    int topHeight = msg.getData().getInt("topHeight");

                    if (locationY <= topHeight && (topPanel.getVisibility() == View.GONE || topPanel.getVisibility() == View.INVISIBLE)) {
                        topPanel.setVisibility(View.VISIBLE);
                    }

                    if (locationY > topHeight && topPanel.getVisibility() == View.VISIBLE) {
                        topPanel.setVisibility(View.GONE);
                    }
                    break;

            }


        }
    };


    public void vod_classClickListener(ArrayList<vod_class_C> vod_class_cs) {


        vodClassA = new vod_class_A(R.layout.classify_item, this, vod_class_cs);

        vod_class.setAdapter(vodClassA);
        vod_class.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                //Toast.makeText(getContext(), "Click ++ item" + i, Toast.LENGTH_SHORT).show();
                final TextView tv_str = (TextView) view.findViewById(R.id.tv_str);
                String tv_str1 = tv_str.getText().toString();
                tv_class.setText(tv_str1);
                init_Customize(ClassifyUrl(tv_class.getText().toString(), tv_area.getText().toString(), tv_year.getText().toString(), tv_lang.getText().toString()));
            }
        });

    }

    public void vod_langClickListener(ArrayList<vod_lang_C> vod_lang_cs) {


        vodLangA = new vod_lang_A(R.layout.classify_item, this, vod_lang_cs);

        vod_lang.setAdapter(vodLangA);
        vod_lang.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                //Toast.makeText(getContext(), "Click ++ item" + i, Toast.LENGTH_SHORT).show();
                final TextView tv_str = (TextView) view.findViewById(R.id.tv_str);
                String tv_str1 = tv_str.getText().toString();
                tv_lang.setText(tv_str1);
                init_Customize(ClassifyUrl(tv_class.getText().toString(), tv_area.getText().toString(), tv_year.getText().toString(), tv_lang.getText().toString()));

            }
        });

    }

    public void vod_areaClickListener(ArrayList<vod_area_C> vod_area_cs) {


        vodAreaA = new vod_area_A(R.layout.classify_item, this, vod_area_cs);

        vod_area.setAdapter(vodAreaA);
        vod_area.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                //Toast.makeText(getContext(), "Click ++ item" + i, Toast.LENGTH_SHORT).show();
                final TextView tv_str = (TextView) view.findViewById(R.id.tv_str);
                String tv_str1 = tv_str.getText().toString();
                tv_area.setText(tv_str1);
                init_Customize(ClassifyUrl(tv_class.getText().toString(), tv_area.getText().toString(), tv_year.getText().toString(), tv_lang.getText().toString()));
            }
        });

    }

    public void vod_yearClickListener(ArrayList<vod_year_C> vod_year_cs) {


        vodYearA = new vod_year_A(R.layout.classify_item, this, vod_year_cs);

        vod_year.setAdapter(vodYearA);
        vod_year.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                //Toast.makeText(getContext(), "Click ++ item" + i, Toast.LENGTH_SHORT).show();
                final TextView tv_str = (TextView) view.findViewById(R.id.tv_str);
                String tv_str1 = tv_str.getText().toString();
                tv_year.setText(tv_str1);
                init_Customize(ClassifyUrl(tv_class.getText().toString(), tv_area.getText().toString(), tv_year.getText().toString(), tv_lang.getText().toString()));
            }
        });

    }


    class vod_class_A extends BaseAdapter implements ListAdapter {
        private ArrayList<vod_class_C> vod_class_cs;
        private int id;
        private Context context;
        private LayoutInflater inflater;

        public vod_class_A(int subpage_item, ClassifyActivity context, ArrayList<vod_class_C> vod_class_cs) {
            this.vod_class_cs = vod_class_cs;
            this.context = context;
            this.id = subpage_item;
            inflater = LayoutInflater.from(context);

        }

        @Override
        public int getCount() {
            return vod_class_cs.size();
        }

        @Override
        public Object getItem(int i) {
            return vod_class_cs.get(i);
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @SuppressLint("WrongConstant")
        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            TextView class_txt = null;
            vod_class_A.ViewHolder viewHolder;
            if (view == null) {
                view = inflater.inflate(id, null);
                class_txt = (TextView) view.findViewById(R.id.tv_str);
                view.setTag(new ViewHolder(class_txt));
            } else {
                vod_class_A.ViewHolder viewHolder1 = (vod_class_A.ViewHolder) view.getTag(); // 重新获取ViewHolder
                class_txt = viewHolder1.class_txt;
            }
            vod_class_C vcs = (vod_class_C) vod_class_cs.get(i); // 获取当前项的实例
            class_txt.setText(vcs.getClass_txt().toString());
            return view;
        }

        private final class ViewHolder {
            TextView class_txt = null;

            public ViewHolder(TextView class_txt) {
                this.class_txt = class_txt;
            }

        }
    }


    class vod_lang_A extends BaseAdapter implements ListAdapter {
        private ArrayList<vod_lang_C> vod_lang_cs;
        private int id;
        private Context context;
        private LayoutInflater inflater;

        public vod_lang_A(int subpage_item, ClassifyActivity context, ArrayList<vod_lang_C> vod_lang_cs) {
            this.vod_lang_cs = vod_lang_cs;
            this.context = context;
            this.id = subpage_item;
            inflater = LayoutInflater.from(context);

        }

        @Override
        public int getCount() {
            return vod_lang_cs.size();
        }

        @Override
        public Object getItem(int i) {
            return vod_lang_cs.get(i);
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @SuppressLint("WrongConstant")
        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            TextView lang_txt = null;
            TextView pgcount = null;
            vod_lang_A.ViewHolder viewHolder;
            if (view == null) {
                view = inflater.inflate(id, null);
                lang_txt = (TextView) view.findViewById(R.id.tv_str);
                view.setTag(new ViewHolder(lang_txt));
            } else {
                vod_lang_A.ViewHolder viewHolder1 = (vod_lang_A.ViewHolder) view.getTag(); // 重新获取ViewHolder
                lang_txt = viewHolder1.lang_txt;
            }
            vod_lang_C vcs = (vod_lang_C) vod_lang_cs.get(i); // 获取当前项的实例
            lang_txt.setText(vcs.getLang_txt().toString());
            return view;
        }

        private final class ViewHolder {
            TextView lang_txt = null;

            public ViewHolder(TextView lang_txt) {
                this.lang_txt = lang_txt;
            }

        }
    }

    class vod_year_A extends BaseAdapter implements ListAdapter {
        private ArrayList<vod_year_C> vod_year_cs;
        private int id;
        private Context context;
        private LayoutInflater inflater;

        public vod_year_A(int subpage_item, ClassifyActivity context, ArrayList<vod_year_C> vod_year_cs) {
            this.vod_year_cs = vod_year_cs;
            this.context = context;
            this.id = subpage_item;
            inflater = LayoutInflater.from(context);

        }

        @Override
        public int getCount() {
            return vod_year_cs.size();
        }

        @Override
        public Object getItem(int i) {
            return vod_year_cs.get(i);
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @SuppressLint("WrongConstant")
        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            TextView year_txt = null;
            TextView pgcount = null;
            vod_year_A.ViewHolder viewHolder;
            if (view == null) {
                view = inflater.inflate(id, null);
                year_txt = (TextView) view.findViewById(R.id.tv_str);
                view.setTag(new ViewHolder(year_txt));
            } else {
                vod_year_A.ViewHolder viewHolder1 = (vod_year_A.ViewHolder) view.getTag(); // 重新获取ViewHolder
                year_txt = viewHolder1.year_txt;
            }
            vod_year_C vcs = (vod_year_C) vod_year_cs.get(i); // 获取当前项的实例
            year_txt.setText(vcs.getYear_txt().toString());
            return view;
        }

        private final class ViewHolder {
            TextView year_txt = null;

            public ViewHolder(TextView year_txt) {
                this.year_txt = year_txt;
            }

        }
    }


    class vod_area_A extends BaseAdapter implements ListAdapter {
        private ArrayList<vod_area_C> vod_area_cs;
        private int id;
        private Context context;
        private LayoutInflater inflater;

        public vod_area_A(int subpage_item, ClassifyActivity context, ArrayList<vod_area_C> vod_area_cs) {
            this.vod_area_cs = vod_area_cs;
            this.context = context;
            this.id = subpage_item;
            inflater = LayoutInflater.from(context);

        }

        @Override
        public int getCount() {
            return vod_area_cs.size();
        }

        @Override
        public Object getItem(int i) {
            return vod_area_cs.get(i);
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @SuppressLint("WrongConstant")
        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            TextView area_txt = null;
            TextView pgcount = null;
            vod_area_A.ViewHolder viewHolder;
            if (view == null) {
                view = inflater.inflate(id, null);
                area_txt = (TextView) view.findViewById(R.id.tv_str);
                view.setTag(new ViewHolder(area_txt));
            } else {
                vod_area_A.ViewHolder viewHolder1 = (vod_area_A.ViewHolder) view.getTag(); // 重新获取ViewHolder
                area_txt = viewHolder1.area_txt;
            }
            vod_area_C vcs = (vod_area_C) vod_area_cs.get(i); // 获取当前项的实例
            area_txt.setText(vcs.getArea_txt().toString());
            return view;
        }

        private final class ViewHolder {
            TextView area_txt = null;

            public ViewHolder(TextView area_txt) {
                this.area_txt = area_txt;
            }

        }
    }


    private void LoadToolbar() {
        Toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(Toolbar);//利用Toolbar代替ActionBar
//        Toolbar.inflateMenu(R.menu.menu_user);
        //设置的点击事件
        Toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //跳转到用户设置页面
                finish();
            }
        });
        //添加menu 菜单点击事件
        Toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.action_save:

                        //得到视频信息
                        //弹出框命名文件
                        //写入数据

                        String ClassifyData = tv_class.getText().toString() + "-" + tv_area.getText().toString() + "-" + tv_year.getText().toString() + "-" + tv_lang.getText().toString();
                        if (!FileoOperations.fileIsExists(filePath + ClassifyData + ".txt")) {

                            //不存在就说明是第一个，组合成json
                            String content = httpdata.getText().toString();
                            //不存在就创建
                            FileoOperations.writeData(filePath, ClassifyData, content);
                            Toast.makeText(ClassifyActivity.this, "离线完成", Toast.LENGTH_SHORT).show();

                        } else {
                            Toast.makeText(ClassifyActivity.this, "已经存在", Toast.LENGTH_SHORT).show();
                        }

                        break;

                }
                return true;
            }
        });

    }

    @Override
    public boolean onCreatePanelMenu(int featureId, Menu menu) {
        getMenuInflater().inflate(R.menu.menu_save, menu);//toolbar添加menu菜单
        return true;
    }


    class vod_class_C {

        private String class_txt;

        public String getClass_txt() {
            return class_txt;
        }

        public void setClass_txt(String class_txt) {
            this.class_txt = class_txt;
        }
    }

    class vod_lang_C {

        private String lang_txt;


        public String getLang_txt() {
            return lang_txt;
        }

        public void setLang_txt(String lang_txt) {
            this.lang_txt = lang_txt;
        }
    }

    class vod_area_C {

        private String area_txt;


        public String getArea_txt() {
            return area_txt;
        }

        public void setArea_txt(String area_txt) {
            this.area_txt = area_txt;
        }
    }


    class vod_year_C {

        private String year_txt;


        public String getYear_txt() {
            return year_txt;
        }

        public void setYear_txt(String year_txt) {
            this.year_txt = year_txt;
        }
    }

}
